package com.leetcode.array_matrix;

/**
 * @author Dennis Li
 * @date 2020/7/30 17:13
 */
public class MajorityElement_169 {

    public int majorityElement(int[] nums) {
        int count = 0;
        int candidate = 0;
        for (int num : nums) {
            if (count == 0)
                candidate = num;
            count += candidate == num ? 1 : -1;
        }
        return candidate;
    }

}
